package logic

import (
	"context"
	"goods/models"

	"goods/goods"
	"goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGoodsDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetGoodsDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGoodsDetailLogic {
	return &GetGoodsDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetGoodsDetailLogic) GetGoodsDetail(in *goods.GetGoodsDetailRequest) (*goods.GetGoodsDetailResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var g models.Goods
	g.ID = uint(in.GoodsId)
	if err = g.Detail(); err != nil {
		logx.Error("商品详情展示失败")
		return nil, err
	}
	return &goods.GetGoodsDetailResponse{
		GoodsId:    int64(g.ID),
		GoodsTitle: g.GoodsTitle,
		GoodsCover: g.GoodsCover,
		GoodsPrice: float32(g.GoodsPrice),
		GoodsSize:  g.GoodsSize,
	}, nil
}
